package org.wtframework.platform.web.mvc.action.impl;

import java.io.UnsupportedEncodingException;

import javax.servlet.http.HttpServletResponse;

import org.openredhead.springx.core.web.mvc.support.ActionValueAssistant;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.wtframework.platform.server.util.WebFileUtil;

import com.google.common.base.Strings;


/**
 * 
 * <B>类描述：</B> （基础数据加Action） <br/><br/>
 * <B>作者：</B> 梁卓文<br/><br/>
 * <B>创建日期：</B> 2014年5月4日 下午4:24:10 
 *
 */
@Controller
@RequestMapping("/base")
public class BaseActionController {
	
	@RequestMapping("/from_templet") 
	public String index(ModelMap modelMap, ActionValueAssistant actionValueAssistant) {

		String url = actionValueAssistant.get(String.class, "templet_url");
		
		return url;
	}	
	
	@RequestMapping("/downFile")
	public void downFile(HttpServletResponse response, ModelMap modelMap, ActionValueAssistant actionValueAssistant) {
		
		String fileUrl = actionValueAssistant.getString("fileUrl");
		String fileName = actionValueAssistant.getString("fileName");
		
		try {
			if (!Strings.isNullOrEmpty(fileName)) {
				fileName = java.net.URLDecoder.decode(fileName, "UTF-8");
			}
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		System.err.println(fileName);
		WebFileUtil.downloadFile(response, fileUrl, fileName);
	}	
	
	@RequestMapping("/common-image-cut")
	public String imageCut(ModelMap modelMap,ActionValueAssistant actionValueAssistant){
		
		modelMap.put("imageUrl", actionValueAssistant.getString("imageUrl"));
		return "demo/pb-cutimage-common";
	}
	
}
